package com.feit.springcloudclient.controller;

import com.alibaba.fastjson.JSONObject;
import com.feit.springcloudclient.pojo.User;
import com.feit.springcloudclient.service.IUserService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhaiding
 * @date 2019/3/14 15:05
 */
@RestController
public class UserContorller {

    @Resource
    private IUserService userService;

    @RequestMapping(value = "/queryAll")
    public List<User> queryAll() {
        return userService.queryAll();
    }

    @RequestMapping(value = "/queryById")
    public User queryById(@RequestParam Integer id) {
        return userService.queryById(id);
    }

    @RequestMapping(value = "/deleteById")
    public String deleteById(@RequestParam Integer id) {
        int result = userService.deleteById(id);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", result);
        return jsonObject.toString();
    }


    @RequestMapping(value = "/save")
    public String save(@RequestBody User user) {
        int result = userService.save(user);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", result);
        return jsonObject.toString();
    }

    @RequestMapping(value = "/updateById")
    public String updateById(@RequestBody User user) {
        int result = userService.updateById(user);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", result);
        return jsonObject.toString();
    }


}
